package com.lx.bbs.dao;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lx.bbs.entity.Reply;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.*;

/**
 * <p>
 * BBS论坛-回帖表-2 Mapper 接口
 * </p>
 *
 * @author lx
 * @since 2024-11-23
 */
public interface ReplyMapper extends BaseMapper<Reply> {


    @Select("SELECT\n" +
            "	a.*,\n" +
            "	b.cname \"user.cname\"," +
            "	b.head  \"user.head\"," +
            "	b.regtime  \"user.regtime\"" +
            "FROM\n" +
            "	tbl_reply a\n" +
            "	JOIN tbl_user b ON a.uid = b.id\n" +
            "WHERE topicid = #{tid}")
    Page<Reply> selectByTid(@Param("tid") int tid, Page<Reply> page);


    @Select("SELECT\n" +
            "	a.*,\n" +
            "	b.cname \"user.cname\",\n" +
            "	b.head \"user.head\",\n" +
            "	b.regtime  \"user.regtime\"\n" +
            "FROM\n" +
            "	tbl_reply a\n" +
            "	JOIN tbl_user b ON a.uid = b.id \n" +
            "WHERE\n" +
            "	replyid = #{rid}")
    @Results(
            id = "rm1",
            // @Many 一对多  fetchType 设置加载方式 默认积极加载
            value = {
                    @Result(column = "id", property = "id", id = true),
                    @Result(column = "replyid", property = "replyid"),
                    @Result(column = "id", property = "children",
                            many = @Many(select = "selectByRid"))}
    )
    Page<Reply> selectByRid(@Param("rid") int rid, Page<Reply> page);
}
